package com.salinity.kun.helper;

import com.salinity.kun.algorithm.harmonic.GaussianElimination;

/**
 * 岭回归分析
 * 
 * @author Administrator
 *
 */
public class RidgeRegressionHelper {

	public static double[][] getRidgeData(double[][] m, double start, double end, int divCount) {
		if (divCount <= 0 || end < start) {
			throw new RuntimeException("The parameter is invalid!");
		}
		double tempC = start;
		double interval = end - start / divCount * 1.0;
		double rslt[][] = new double[divCount][];
		double[][] tempM = new double[m.length][m[0].length];
		double[] x1 = null, x2;
		StringBuilder sb = new StringBuilder();
		int i, j, k, index;

		for (k = 0; k < divCount; k++) {
			tempC = start + interval * k;
			for (i = 0; i < m.length; i++) {
				for (j = 0; j < m[0].length; j++) {
					tempM[i][j] = m[i][j];
				}
				tempM[i][i] += tempC;
			}
			sb.delete(0, sb.length());
			x2 = GaussianElimination.columnMainElimination(tempM);
			if (k != 0) {

				for (index = 0; index < x2.length; index++) {

					sb.append(x2[index]).append(",");
				}
				sb.delete(sb.length() - 1, sb.length());

				System.out.println(sb.toString());
			}
			x1 = x2;

		}
		return rslt;

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
